<template>
	<view class="page">
		<view>{{myData.date}}读后感:</view>
		<textarea class="content" placeholder-style="color:#c1c1c1" placeholder="请点击输入文字" v-model="myData.content"/>
		<view style="margin-top: 100rpx;">
			<button type="primary" @click="save">保存文字</button>
		</view>
	</view>
</template>

<script>
	import DB from '@/common/sqlite.js'

	export default {
		data() {
			return {
				//保存的数据
				myData:{
					date:'',
					content:''
				}
				
			}
		},
		methods: {
			save(){
				console.log('保存中。。。。')
				uni.showToast({
					title:'正在保存' 
				})
				DB.insertTableData('myNote', this.myData.date+'\' , \''+this.myData.content+' ').then(res=>{
					console.log('insert',res)
					uni.navigateBack()
				},err=>{
					console.log('insert err',err)
				})
				
				
				 
				
			},
			formartDate(param){
				let date = new Date(param);
					let Y = date.getFullYear() + '-';
					let M = date.getMonth()+1 < 10 ? '0' + (date.getMonth() + 1)  + '-' : date.getMonth() +1 + '-' ;
					let D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' ';
					let h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
					let m = date.getMinutes() <10 ? '0' + date.getMinutes() + ':' :date.getMinutes() + ':';
					let s = date.getSeconds() <10 ? '0' + date.getSeconds() : date.getSeconds();
					return Y +M +D + h + m + s;
				 
				}
			 
		},
		onShow() {
			this.myData.date=this.formartDate(new Date()) 
		}
	}
</script>

<style>
	.page{
		padding: 20rpx;
	}
	
	.content{
		border: 1px solid #ececec;
		width: 98%;
		padding: 10rpx;
		height: 600rpx;
	}
</style>
